/*
 ============================================================================
 Name		: Area.h
 Author	  : Lenka Litvova
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CArea declaration
 ============================================================================
 */

#ifndef AREA_H
#define AREA_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <ncvImage.h> //NokiaCV CNokiaCVImage Class
#include <e32hashtab.h> //for RHashMap

// CLASS DECLARATION

/**
 *  CArea
 *  Class representating an area in an image.
 */
class CArea : public CBase
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CArea();

	/**
	 * Two-phased constructor.
	 */
	static CArea* NewL(TPoint aBegin, TInt aHeight);

	/**
	 * Two-phased constructor.
	 */
	static CArea* NewLC(TPoint aBegin, TInt aHeight);
	
	/**
	 * Function returning width of this area.
	 */
	inline TInt GetWidth(){ return iRight.iX - iLeft.iX; }
	
	/**
	  * Function returning height of this area.
	  */
	inline TInt GetHeight(){ return iBottom.iY - iTop.iY; }
	
	/**
	 * Function return number of points beloning to this area.
	 */
	inline TInt GetSize() { return iSize;}
	
	/**
	 * Returns coordinates of the top pixel in the image.
	 */
	inline TPoint GetTop() {return iTop;}
	
	/**
	  * Returns coordinates of the bottom pixel in the image.
	  */
	inline TPoint GetBottom() {return iBottom;}
	
	/**
	  * Returns coordinates of the left most pixel in the image.
	  */
	inline TPoint GetLeft() {return iLeft;}
	
	/**
	  * Returns coordinates of the right most pixel in the image.
	  */
	inline TPoint GetRight() { return iRight;}
	
	/**
	 * Returns array with left border point of this area.
	 */
	inline RHashMap<TInt, TPoint>* GetBordersLeft(){return iBorders_left;}
	
	/**
	 * Returns array with right border point of this area.
	 */
	inline RHashMap<TInt, TPoint>* GetBordersRight(){return iBorders_right;}
	
	/**
	 * Returns coordinates of left most pixel of the area at the specified line.
	 */
	inline TPoint GetLeftBorderL(TInt aRow){ return iBorders_left->FindL(aRow);}
	
	/**
	  * Returns coordinates of right most pixel of the area at the specified line.
	  */
	inline TPoint GetRightBorderL(TInt aRow){ return iBorders_right->FindL(aRow);}
	
	/**
	 * Adds point to area and updates its borders.
	 */
	void Update(TPoint aPoint);
	
	/**
	 * Function count the resulting border after all point have been added to this area.
	 */
	void Finish();
	
	/**
	 * Function merge this area with other area on the same image. Borders are update
	 * so that this area contains point from the merged area too.
	 */
	void Merge(CArea *aArea);
	
	/**
	 * Function changes the color of pixels near the border of this area to the clear color.
	 */
	void ClearBorder(CFbsBitmap *aImage, TRgb aClearColor);
	
	void ClearBorderCV(CNokiaCVImage *aImage, TRgb aClearColor);
	
	/**
	 * Funtion repairs the the position of the most left and right pixel so that they
	 * are on the same line.
	 */
	void Equalize();
	
	/**
	 * Function draw its borders on the specified image;
	 */
	void DrawArea(CNokiaCVImage *aImage);
	
	void DrawRect(CNokiaCVImage *aImage);
	
	void DrawBorder (CNokiaCVImage *aImage);

private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CArea();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL(TPoint aBegin, TInt aHeight);
	
private:
	TPoint iTop;
    TPoint iBottom;
    TPoint iLeft;
    TPoint iRight;
    TInt iSize;
    RHashMap<TInt, TPoint> *iBorders_left;
    RHashMap<TInt, TPoint> *iBorders_right;
    //CArrayFixFlat<TPoint> *iBorders_left;
   // CArrayFixFlat<TPoint> *iBorders_right;
	
public:
	TPoint iTop_from;
    TPoint iTop_to;
    TPoint iBottom_from;
    TPoint iBottom_to;

	};

#endif // AREA_H
